<?php 
get_header();
get_sidebar();
?>
    <div id="content">
		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
			<div id="post-<?php the_ID(); ?>" <?php post_class('par'); ?>>	
			<?php

			if (function_exists('has_post_format') && has_post_format( 'aside' )) {
				echo the_content();
			}

			elseif (function_exists('has_post_format') && has_post_format( 'chat' )) {
				?>
				<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
				<span class="emph"><?php the_date(); ?></span>
				<br />
				<?php the_excerpt(); ?>
				<?php
			}

			elseif (function_exists('has_post_format') && has_post_format( 'gallery' )) {
				?>
				<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
				<span class="emph"><?php the_date(); ?></span>
				<br />
				<?php if(has_post_thumbnail()) {
					the_post_thumbnail('medium');
				} else {
				global $wpdb;
					$attachment_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post->ID' AND post_type='attachment' ORDER BY post_date DESC LIMIT 1");
					if ($attachment_id) {
					echo wp_get_attachment_image($attachment_id, 'medium', true);
					}
				}	
				?>
				<p class="postmetadata">Category: <?php the_category(', ') ?> <br />  
				<?php the_tags(); ?> <br /> 
				<?php edit_post_link('Edit','',''); ?> <br />
				<?php comments_popup_link('Comments', 'Comments (1)', 'Comments (%)'); ?></p>
			
				<?php
			}

			elseif (function_exists('has_post_format') && has_post_format( 'image' )) {
				?>
				<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
				<span class="emph"><?php the_date(); ?></span>
				<br />
				<?php if(has_post_thumbnail()) {
					the_post_thumbnail('medium');
				} else {
				global $wpdb;
					$attachment_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post->ID' AND post_type='attachment' ORDER BY post_date DESC LIMIT 1");
					if ($attachment_id) {
					echo wp_get_attachment_image($attachment_id, 'medium', true);
					}
				}	
				?>
				<p class="postmetadata">Category: <?php the_category(', ') ?> <br />  
				<?php the_tags(); ?> <br /> 
				<?php edit_post_link('Edit','',''); ?> <br />
				<?php comments_popup_link('Comments', 'Comments (1)', 'Comments (%)'); ?></p>
			
				<?php
			}

			elseif (function_exists('has_post_format') && has_post_format( 'link' )) {
				?>
				<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
				<br /><br />
				<?php the_content(); ?>
				<?php
			}

			elseif (function_exists('has_post_format') && has_post_format( 'quote' )) {
				echo the_content();
			}

			elseif (function_exists('has_post_format') && has_post_format( 'status' )) {
  				echo the_content();
			}

			elseif (function_exists('has_post_format') && has_post_format( 'video' )) {
				?>
				<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
				<?php the_content(); ?>
				<p class="postmetadata">Category: <?php the_category(', ') ?> <br />  
				<?php the_tags(); ?> <br /> 
				<?php edit_post_link('Edit','',''); ?> <br />
				<?php comments_popup_link('Comments', 'Comments (1)', 'Comments (%)'); ?></p>
			
				<?php
			}

			elseif (function_exists('has_post_format') && has_post_format( 'audio' )) {
				?>
				<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
				<?php the_content(); ?>
				<p class="postmetadata">Category: <?php the_category(', ') ?> <br />  
				<?php the_tags(); ?> <br /> 
				<?php edit_post_link('Edit','',''); ?> <br />
				<?php comments_popup_link('Comments', 'Comments (1)', 'Comments (%)'); ?></p>
			
				<?php
			}

			else {
		?>
				<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
				<span class="emph"><?php the_date(); ?></span>
				<br />
			<?php if(has_post_thumbnail()) {
					the_post_thumbnail();
				} else {
				global $wpdb;
					$attachment_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post->ID' AND post_type='attachment' ORDER BY post_date DESC LIMIT 1");
					if ($attachment_id) {
					echo wp_get_attachment_image($attachment_id, 'thumbnail', true);
					}
				}	
			?>
			<?php the_excerpt(); ?>
				<p class="postmetadata">Category: <?php the_category(', ') ?> <br />  
				<?php the_tags(); ?> <br /> 
				<?php edit_post_link('Edit','',''); ?> <br />
				<?php comments_popup_link('Comments', 'Comments (1)', 'Comments (%)'); ?></p>
			
		<?php 
			}
		?>
		<p class="secbot"><a href="#mainmenu" title="go left to menu">return to menu</a></p>
		</div>
		<?php endwhile;?>
		<?php 
		get_footer();
		?>
		<?php else: ?>
		<div class="par">
		<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
		</div>
		<?php endif; ?>
<?php 
get_footer();
?>
